import Cookies from 'js-cookie'
import { decrypt } from '@/utils/jsencrypt'
import modal from '@/plugins/modal'

export default (that) => {
  return new Promise((resolve, reject) => {
    that
      .$prompt('登录确认', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        inputPattern: /\S+/,
        inputErrorMessage: '登录密码必填',
        inputType: 'password',
        inputPlaceholder: '请输入登录密码'
      })
      .then(({ value }) => {
        const password = Cookies.get('checkPassWord')
        if (decrypt(password) !== value) {
          modal.msgError(`密码错误`)
          return
        }
        Cookies.set('loginCheck', true, { expires: 1 })
        resolve('ok')
      })
      .catch((error) => {
        reject(error)
      })
  })
}
